﻿

namespace OfficeClip.OpenSource.StyleFix.Drivers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class StyleCopRules
    {
        public StyleCopRules()
        {
            ForceAllow = false;
            RuleFound = false;
        }

        public bool ForceAllow
        {
            get;
            set;
        }

        public bool RuleFound
        {
            get;
            set;
        }

        protected bool IsAllowed(string errorId)
        {
            return !ForceAllow && !(new Configure()).IsSAAllowed(errorId);
        }

        protected bool IsLineViolated(SFWorkingLine workingLine, string errorId)
        {
            if (IsAllowed(errorId))
            {
                return false;
            }

            List<SAObject> violations = workingLine.Violations.FindAll(sao => sao.ErrorId == errorId);
            bool returnValue = (violations != null) && (violations.Count >= 1);
            if (returnValue)
            {
                foreach (SAObject violation in violations)
                {
                    violation.IsFixed = true;
                }
            }
            if (returnValue)
                RuleFound = true;
            return returnValue;
        }
    }
}
